package com.yanqu.road.server.cmd.union.cross.huaben;

import com.yanqu.road.entity.union.huaben.server.UnionHuaBenPatronsData;
import com.yanqu.road.pb.union.cross.UnionHuaBenProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.union.cross.UnionHuaBenModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.Map;

@Cmd(code = Protocol.S_CROSS_UNION_HUA_BEN_PATRONS_TIMES, desc = "门客次数")
public class UnionHuaBenPatronsTimesCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {


        UnionHuaBenProto.UnionHuaBenPatronsTimesRespMsg.Builder respMsp = UnionHuaBenProto.UnionHuaBenPatronsTimesRespMsg.newBuilder();
        respMsp.setRet(0);

        Map<Integer, UnionHuaBenPatronsData> patronsDataMap = player.getModule(UnionHuaBenModule.class).getPatronsDataMap();
        for (Map.Entry<Integer, UnionHuaBenPatronsData> dataEntry : patronsDataMap.entrySet()) {
            UnionHuaBenProto.UnionHuaBenPatronsTimesTemp.Builder builder = UnionHuaBenProto.UnionHuaBenPatronsTimesTemp.newBuilder();
            UnionHuaBenPatronsData patronsData = dataEntry.getValue();
            builder.setPatronsId(patronsData.getPatronsId());
            builder.setSendTimes(patronsData.getSendTimes());
            respMsp.addPatronsTimes(builder);
        }

        player.sendPacket(Protocol.U_CROSS_UNION_HUA_BEN_PATRONS_TIMES, respMsp);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
